﻿//Provides a registry of available Plugin classes indexed by a mnemonic(助记符) code known as the Plugin's ptype. 
//The xtype provides a way to avoid instantiating child Components when creating a full, 
//nested config object for a complete Ext page.
Ext.PluginMgr = new Ext.AbstractManager({
    typeName: 'ptype',

    //创建插件实例
    create: function (config, defaultType) {
        var PluginCls = this.types[config.ptype || defaultType];//通过ptype指定的类型或默认类型获取插件类
        if (PluginCls.init) {//如果插件类有init方法，直接返回插件类
            return PluginCls;
        } else {//否则创建一个插件实例返回
            return new PluginCls(config);
        }
    },

    //根据type返回所有对应的插件，type不紧紧是'ptype'类型，可以是其他类型
    findByType: function (type, defaultsOnly) {
        var matches = [],
            types = this.types; //在父类的构造函数中，this.types = {};

        for (var name in types) {
            if (!types.hasOwnProperty(name)) {
                continue;
            }
            var item = types[name];

            //如果defaultType为true，则只返回那些isDefault属性为真的插件
            if (item.type == type && (!defaultsOnly || (defaultsOnly === true && item.isDefault))) {
                matches.push(item);
            }
        }

        return matches;
    }
});


Ext.preg = function () {
    return Ext.PluginMgr.registerType.apply(Ext.PluginMgr, arguments);
};